package com.linjiahao.oss.controller;

import com.linjiahao.commonutils.ResultMap;
import com.linjiahao.oss.service.FileService;
import com.linjiahao.oss.vo.EditorUploadVO;
import com.linjiahao.oss.vo.TbTestStateSecretPO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(description="阿里云文件管理")
@RestController
@RequestMapping("/eduoss/file")
public class FileController {

    @Autowired
    private FileService fileService;

        /**
         * 文件上传
         *
         * @param file
         */
    @ApiOperation(value = "文件上传")
    @PostMapping("upload")
    public ResultMap upload(@ApiParam(name = "file", value = "文件", required = true)
        @RequestParam("file") MultipartFile file) {
        String uploadUrl = fileService.upload(file);
        //返回r对象
        return ResultMap.ok().message("文件上传成功").data("url",uploadUrl);

    }

    /**
     * 富文本文件上传
     *
     * @param file
     */
    @ApiOperation(value = "文件上传")
    @PostMapping("upload2")
    public EditorUploadVO upload2(@ApiParam(name = "file", value = "文件", required = true)
                                 @RequestParam("file") MultipartFile file) {
        String uploadUrl = fileService.upload(file);
        String uploadUrlArr[] = {uploadUrl};
        EditorUploadVO editorUploadVO = new EditorUploadVO();
        editorUploadVO.setErrno(0);
        editorUploadVO.setData(uploadUrlArr);
        //返回r对象
        return  editorUploadVO;

    }


    @ApiOperation(value = "文件上传")
    @PostMapping("test1")
    public TbTestStateSecretPO insertPO(@RequestBody TbTestStateSecretPO tbTestStateSecretPO) {
        return  fileService.insertPO(tbTestStateSecretPO);

    }

    @ApiOperation(value = "文件上传")
    @PostMapping("test2")
    public TbTestStateSecretPO getPO(@RequestBody TbTestStateSecretPO tbTestStateSecretPO) {
        return  fileService.getPO(tbTestStateSecretPO);

    }

    @ApiOperation(value = "文件上传")
    @PostMapping("test3")
    public TbTestStateSecretPO updatePO(@RequestBody TbTestStateSecretPO tbTestStateSecretPO) {
        return  fileService.updatePO(tbTestStateSecretPO);

    }
}
